package actions;

import gui.Frame;
import information.Job;

import java.awt.event.ActionEvent;

import javax.swing.AbstractAction;
import javax.swing.JComboBox;

/**
 * An action used for applying for a specific level for a specific job.
 * @author Natalie
 *
 */
@SuppressWarnings("serial")
public class ApplyAction extends AbstractAction {

	private Frame myFrame;
	private Job myJob;
	/**
	 * The combo box for the volunteer to choose a level.
	 */
	private JComboBox myLevel;
	
	public ApplyAction(final Frame theFrame, final Job theJob, final JComboBox theLevel) {  
	    super("Apply");
	    myFrame = theFrame;
	    myJob = theJob;
	    myLevel = theLevel;
	    
	  }
	
	/**
	 * Adds the user to the level selected in the combobox. Displays a message
	 * if they have been successfully added. 
	 */
	@Override
	public void actionPerformed(final ActionEvent theEvent) {
		int level = 0;
		if(myLevel.getSelectedItem().equals("light")) level = 0;
		if(myLevel.getSelectedItem().equals("medium")) level = 1;
		if(myLevel.getSelectedItem().equals("heavy")) level = 2;
		if (myFrame.getData().addToJob(myJob, level)) myFrame.displaySuccess("You have successfully been signed-up for this job! ");
	}

}
